﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChainofResponsibilitySFIStudy
{
    public abstract class Support
    {
        private String name;
        private Support next;
        public Support(String name)
        {
            this.name = name;
        }
        public Support setNext(Support next)
        {
            this.next = next;
            return next;
        }
        public void support(Trouble trouble)
        {
            if (resolve(trouble))
            {
                done(trouble);
            }
            else if (next != null)
            {
                next.support(trouble);
            }
            else
            {
                fail(trouble);
            }    
        }
        public string toString()
        {
            return "[" + name + "]";
        }
            
        protected abstract Boolean resolve(Trouble trouble);
        protected void done(Trouble trouble){
            System.Console.WriteLine(trouble.toString() + " is resolved by " + this.name +  ".");
        }
        protected void fail(Trouble trouble)
        {
            System.Console.WriteLine(trouble.toString() + " cannnot be resolved.");
        }
        

    }
}
